<template>
	<view>
		<view class="box">
			<view v-if="ordersList.length === 0" >
				<kevy-empty :show="true" image="https://img01.yzcdn.cn/vant/empty-image-default.png" text="暂时没有可派送订单哦~"></kevy-empty>
			</view>
			<view class="box" v-for="item in ordersList" :key="item.id" style="margin-bottom: 10rpx;">
				<view style="display: flex; align-items: baseline; margin-bottom: 10rpx;">
					<view style="flex: 1; font-size: 46rpx;">
						{{ item.businessName }}
					</view>
					<view v-if="item.status != '待评价'" style="font-size: 24rpx; color: #666;">{{ item.status }}</view>
					<view v-if="item.status === '待评价'" style="font-size: 24rpx; color: #666;">用户已收货</view>
				</view>
				<view style="display: flex; align-items: center; grid-gap: 20rpx;">
					<view>
						<image style="display: block; width: 160rpx;height: 160rpx; border-radius: 10rpx;"
							:src="item.cover"></image>
					</view>
					<view style="flex: 1;">
						{{ item.name }}
					</view>
					<view>
						本单跑腿金额￥<text style="font-size: 36rpx; font-weight: bold; color: red;">{{ item.actual * 0.2 }}</text>
					</view>
				</view>
				<view style="margin-top: 32rpx;">
					<uni-card is-full="false">
						<view style="color: brown;">地址：{{ item.address }}</view>
						<view style="margin-top: 10rpx;">下单时间：{{ item.payTime }}</view>
					</uni-card>
				</view>
			
				<view style="display: flex; min-height: 40rpx;">
					<view style="padding-top: 20rpx; flex: 1; text-align: right;">
						<uni-tag v-if="item.status === '派送中'" text="已送达" size="mini" type="success" inverted="true"
							@click="changeStatus(item, '待收货')"></uni-tag>
					</view>
				</view>
			</view>
		</view>
				
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ordersList:[],
			}
		},
		onShow(){
			this.loadOrders()
		},
		methods: {
			loadOrders(){
				let status = '派送订单'
				this.$request.get("/orders/selectAll",{
					status: status
				}).then(res => {
					this.ordersList = res.data || []
					console.log(res.data)
				})
			},
			changeStatus(orders,status){
				let form = JSON.parse(JSON.stringify(orders))
				form.status = status
				this.$request.put('/orders/update', form).then(res => {
					if (res.code === '200') {
						uni.showModal({
							title: "送达成功",
							content: "商品已成功送达，用户确认收货之后配送费将会自动存入您的余额中"
						})
						this.loadOrders()
					} else {
						uni.showToast({
							icon: "error",
							title: res.msg
						})
					}
				})
			}
		}
	}
</script>

<style>

</style>
